// JavaScript Document
window.onload = setupLightbox;
var lightboxOverlay; var lightboxImage;

function setupLightbox() {
for (i in document.links) {
	if (document.links[i].rel == "lightbox") { document.links[i].onclick = showLightbox;
}
}
}

function showLightbox() {
lightboxOverlay = document.createElement("div");
lightboxImage = document.createElement("img");

lightboxOverlay.style.position = "fixed";
lightboxOverlay.style.top = lightboxOverlay.style.left ="0"; 
lightboxOverlay.style.width = lightboxOverlay.style.height = "100%";
lightboxOverlay.style.background = "#000";
lightboxOverlay.style.opacity = "0.5";
lightboxOverlay.style.filter = "alpha(opacity = 50)";
document.body.appendChild(lightboxOverlay);
lightboxImage.src = this.href;

lightboxImage.onload = showImage;
lightboxOverlay.onclick = closeLightbox;
  return false;
}

function showImage() {
lightboxImage.style.position = "fixed";
lightboxImage.style.top = lightboxImage.style.left = "50%";
lightboxImage.style.marginLeft = -lightboxImage.width/2 + "px";
lightboxImage.style.marginTop = -lightboxImage.height/2 + "px";
lightboxImage.style.border = "10px solid #fff";
document.body.appendChild(lightboxImage);
}

function closeLightbox() {
lightboxImage.style.opacity = lightboxOverlay.style.opacity = "0";
setTimeout( function() {
lightboxImage.parentNode.removeChild(lightboxImage);
lightboxOverlay.parentNode.removeChild(lightboxOverlay);
}, 1);
}
